class StatementsController < ApplicationController
  def create
    user = User.find_by_id(session[:user_id])
    category = Category.find_by_id(params[:category])
    @statements = Statement.new
    statement_voter = StatementVoter.new
    @statements.message = params[:message]
    statement_voter.member_voter = 0
    @statements.agree = 0
    @statements.disagree = 0
    @statements.category = (category)
    user.statements << (@statements)
    if @statements.valid?
      if @statements.save
        @statements.statement_voters << (statement_voter)
        flash[:statements_ss] = "Statement has been added"
      end
    else
      flash[:statements_err] = "The Statement is not valid"
    end
    redirect_to :controller =>"workspaces", :action =>"statement"
  end

  def index
    @category = Category.all
    if !params[:cat].nil?
      @statement  = Statement.paginate(:all, :per_page => 10,:page => params[:page],:conditions =>["category_id = ?",params[:cat]])
    else
      @statement  = Statement.paginate(:all, :per_page => 10,:page => params[:page])
    end
  end
end
